package com.itycu.server.service.business;

import java.util.List;
import com.itycu.server.utils.DateUtils;
import com.itycu.server.dto.business.PraPracticeDto;
import com.itycu.server.core.AbstractService;
import com.itycu.server.utils.SecurityUtils;
import javax.annotation.Resource;

import com.itycu.server.utils.StringUtils;
import org.springframework.stereotype.Service;
import com.itycu.server.mapper.business.PraPracticeMapper;
import com.itycu.server.domain.business.PraPractice;

/**
 * 练习Service业务层处理
 *
 * @author itycu
 * @date 2025-02-18
 */
@Service("praPracticeService")
public class PraPracticeService extends AbstractService<PraPractice> {
    @Resource
    private PraPracticeMapper praPracticeMapper;

    /**
     * 查询练习列表
     *
     * @param praPractice 练习
     * @return 练习
     */
    public List<PraPracticeDto> list(PraPractice praPractice) {
        praPractice.setOrderByClause("id desc");
        return praPracticeMapper.listByCondition(praPractice);
    }

    /**
     * 根据id获取练习详细信息
     */
    @Override
    public PraPracticeDto findById(Long id) {
        return praPracticeMapper.findById(id);
    }

    /**
     * 保存练习
     *
     * @param praPractice 练习
     * @return 结果
     */
    @Override
    public int save(PraPractice praPractice) {
        int count;
        if (praPractice.getId() == null) {
            praPractice.setCreateBy(SecurityUtils.getUserId());
            praPractice.setCreateTime(DateUtils.getNowDate());
            count = super.save(praPractice);
        } else {
            praPractice.setUpdateBy(SecurityUtils.getUserId());
            praPractice.setUpdateTime(DateUtils.getNowDate());
            count = super.update(praPractice);
        }
        return count;
    }

    public PraPracticeDto findById1(Long id) {
        return praPracticeMapper.findById1(id);
    }
}
